package com.amarsoft.apot.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Description: 获取项目初始化的时候Spring帮你创建的所有beanName
 * @title: ApplicationAwareFor
 * @Author szh
 * @Date: 2021/12/23 13:46
 * @Version 1.0
 */
@Component
public class ApplicationAwareFor implements ApplicationContextAware, InitializingBean {

    private ApplicationContext applicationContext;


    @Override
    public void afterPropertiesSet() throws Exception {

        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println("Spring容器加载获取的实例化对象>>>>>>>>>>>>>" + beanDefinitionName);
        }
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
